package net.tycmc.cty.ctyms.timejob.iems.soa.client.vclbase;

import java.util.Map;
import java.util.Set;

import net.tycmc.cty.ctyms.timejob.common.Map2XML;

/**
 * CTY统一服务业务处理
 * @author chengshichao
 *
 */
public class VclBaseHandler {
	
	private IVclBase vclBase;
	
	/**
	 * 添加机械
	 * @param map
	 * @return
	 */
	public Map<String,Object> add_Vcl_Info(Map<String,Object> map){
		StringBuffer xmlReq = new StringBuffer();
		xmlReq.append("<?xml version=\"1.0\" encoding=\"utf-16\"?>");
		xmlReq.append("<Parameter xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\">");
		Set<String> keySet = map.keySet();
		for(String key:keySet){
			xmlReq.append("<"+key+">");
			xmlReq.append(map.get(key));
			xmlReq.append("</"+key+">");
		}
		xmlReq.append("</Parameter>");
		System.out.println(xmlReq);
		//请求
		String xmlRlt = vclBase.Add_Vcl_Info(xmlReq.toString());
		Map<String,Object> mapRlt = Map2XML.xml2Map(xmlRlt);
		return mapRlt;
	}
	
	/**
	 * 业务操作，支持【修改机械、安装终端、拆除终端】
	 * @param map
	 * @param oprtType 1：修改机械    2：安装终端    3：拆除终端
	 * @return
	 */
	public Map<String,Object> oprtHandler(Map<String,Object> map,int oprtType){
		String xmlReq = Map2XML.map2XMLStr(map, "Parameter").replace("UTF-8", "UTF-16");;
		//请求，根据操作类型调用不同的方法
		String xmlRlt = "";
		switch(oprtType){
			case 1:
				xmlRlt = vclBase.Update_Vcl_Info(xmlReq.toString());
			break;
			case 2:
				xmlRlt = vclBase.Add_Install_Info(xmlReq.toString());
			break;
			case 3:
				xmlRlt = vclBase.Tmnl_Backout_Info(xmlReq.toString());
			break;
		}
		Map<String,Object> mapRlt = Map2XML.xml2Map(xmlRlt);
		return mapRlt;
	}
	
	public IVclBase getVclBase() {
		return vclBase;
	}
	public void setVclBase(IVclBase vclBase) {
		this.vclBase = vclBase;
	}
}
